package com.vijay.extension.spring;

import com.vijay.extension.spi.SpiLoader;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class BeanDefinitionPostProcessor implements BeanDefinitionRegistryPostProcessor {

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

        try {
            String locationPattern = "classpath*:com/vijay/extension/service/**/*.class";
            new SpiLoader(locationPattern).load(registry);
        } catch (Exception e) {
            throw new BeanCreationException(e.getMessage(),e);
        }
    }


    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {


    }
}
